from PySide6.QtCore import (Qt,QObject,QMetaObject,
                            Signal,Slot,
                            QThread,QThreadPool,QTimer,
                            QTemporaryFile,QTemporaryDir,
                            QJsonArray,QJsonDocument,QJsonParseError,QJsonValue,
                            QFile,QFileDevice,QIODevice,QIODeviceBase)


class WorkerThread(QThread):
    
    def __init__(self, parent = None):
        super().__init__(parent)
    
    def run(self):
        print("线程任务完成!")
        
        # 线程任务完成，会自动发送信号的,无需手动发送,手动发送可能会导致发送两遍信号.
        # self.finished.emit()
    


class Qt_Custom_Staff_Class(QObject):
    Start_Task = Signal()
    Task_Finsh = Signal()
    Current_Completion_Process = Signal(int)
    Emergency_Stop = Signal()
    OnlyRun = Signal()
        
    def __init__(self, parent=None):
        super().__init__(parent)
        self.Start_Task.connect(self.RunTask)
        
    @Slot(str)
    def solt_fun(self,text):
        print(f"我是槽函数,我是 {text}")

    # 设置员工属性
    def Set_Staff_Attribute(self,**kwargs):
        pass

    def RunTask(self):
        self.workerthread = WorkerThread(parent=self)   # 添加父对象,可以实现自动销毁.
        self.workerthread.finished.connect(lambda : self.Task_Finsh.emit())
        self.workerthread.finished.connect(self.workerthread.deleteLater)  # 添加任务完成就删除线程,减少内存占用.
        self.workerthread.start()
        
        # 在外面实例化该对象的时候,最好就是也接受一个信号,这样子就可以在线程任务完成之后,自动销毁当前对象.